<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/js/layui-v2.4.5/layui/css/layui.css}" media="all" />
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all" />
</head>
<body  style="-webkit-backface-visibility: hidden;">

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修改密码</legend>
</fieldset>

<form class="layui-form"  lay-filter="example">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input layui-disabled layui-btn-disabled">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">旧密码</label>
        <div class="layui-input-block">
            <input type="password" name="oldPassword" lay-verify="required" placeholder="请输入" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            <input type="password" name="newPassword" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">确认新密码</label>
        <div class="layui-input-block">
            <input type="password" name="cofirmPassword" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="text-align: center">
            <button   class="layui-btn" lay-submit lay-filter="save">保存</button>
        </div>
    </div>
</form>


<script th:src="@{/js/jquery-2.1.1.min.js}"></script>
<script th:src="@{/js/layui-v2.4.5/layui/layui.js}"></script>
<script th:src="@{/js/utils.js}"></script>
<script th:inline="javascript">
    var username = [[${username}]];
</script>
<script>
    layui.use(['form'], function(){
        var form = layui.form
            ,layer = layui.layer,
        $ = layui.jquery;

        //监听提交
        form.on('submit(save)', function(data){

            if(data.field.cofirmPassword!=data.field.newPassword){
                layer.msg("新旧密码不一致",{icon: 5})
                return false;
            }
            $.ajax({
                type: "POST",
                url:  path+'/users/changePassword',
                dataType:"json",
                data:data.field,
                success: function (json) {
                    if(json.msg=="保存成功"){
                        layer.msg(json.msg,{icon: 6})
                    }else{
                        layer.msg(json.msg,{icon: 5})
                    }
                },
                error: function (msg) {
                }
            });
            return false;
        });

        //表单初始赋值
        form.val('example', {
            "username": username
        })


    });
</script>

</body>
</html>